import React, { Component } from 'react'
import { Table, Tag, Space } from 'antd';
import { remark, user } from '../../api/index'
import { getCourseListApi } from '../../api/course/course'

export default class Remark extends Component {
    state = {
        columns: [
            {
                title: '用户名',
                dataIndex: 'userId',
                render: data => {
                    let item = this.state.user
                    for (var i = 0; i < item.length; i++) {
                        if (data === item[i].id) {
                            return <span>{item[i].account}</span>
                        }
                    }
                },
            },
            {
                title: '课程名称',
                dataIndex: 'courseId',
                render: data => {
                    let item = this.state.course
                    for (var i = 0; i < item.length; i++) {
                        if (data === item[i].id) {
                            return <span>{item[i].name}</span>
                        }
                    }
                },
            },
            {
                title: '评论内容',
                dataIndex: 'content',
            },
            {
                title: '评论时间',
                dataIndex: 'remarkTime',
            },
            {
                title: '评分',
                dataIndex: 'score',
            },
        ],
        list: [],
        user: [],
        course: []
    }
    componentDidMount() {
        this.getMsg()
    }
    getMsg = async () => {
        const data = await remark.getRemarkList()
        const data1 = await user.getUserListApi()
        const data2 = await getCourseListApi()
        console.log(19191, data2);
        this.setState({ list: data.records, user: data1, course: data2.records })
    }
    render() {
        const { columns, list } = this.state
        return (
            <div>
                <Table rowKey='id' columns={columns} dataSource={list} />
            </div>
        )
    }
}
